<?php
/*
nCore PHP
Copyright (C) 2012  Nikos Siatras

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.*/

class NCore
{

    private $fRootPath; // Root path

    /**
     * Constructs a new NCore framework
     */

    public function __construct()
    {
        // Find root path
        $rootPath = "";
        while (file_exists($rootPath . "index.php") == false)
        {
            $rootPath .= "../";
        }

        $this->fRootPath = $rootPath;
        define('__ROOT__', $rootPath);
    }

    /**
     * Import an NCore library
     * @param string $classPath is the path of the class library
     */
    public function Import($path)
    {
        $path = str_replace(__ROOT__ . "nCore/", "", $path);
        $path = __ROOT__ . "nCore/" . $path . "/";

        $pathFilesAndFolders = scandir($path);

        for ($i = 0; $i < sizeof($pathFilesAndFolders); $i++)
        {
            $filename = $pathFilesAndFolders[$i];
            $filePath = $path . $filename;

            if (is_file($filePath))
            {
                require_once($filePath);
            }
            else if ($filename != "." && $filename != "..")
            {
                $this->Import($filePath);;
            }
        }
    }

}

?>
